# 测试用例一：
# 1、输入账号，输入密码，点击登录
# 2、点击用户-用户分组-添加分组为：社会琳
# http://121.40.86.4:8899/admin
# 账号:admin  密码：Aa010903!
import uuid
import time
from selenium import webdriver
from selenium.webdriver.common.by import By
class CRMEB:
    uuid_ = str(uuid.uuid4()).split('-')[0]  # 50e2f5a9
    def __init__(self,driver,url):
        self.driver = driver
        # 初始化驱动
        self.driver = webdriver.Chrome()
        # 打开网页
        self.driver.get(url)
        # 设置隐式等待
        self.driver.implicitly_wait(15)
        # 最大化窗口
        self.driver.maximize_window()
    def login(self,user:str,password:str):
        # 输入账号：
        self.driver.find_elements(By.CLASS_NAME, "el-input__inner")[0].send_keys(user)
        # 输入密码：
        self.driver.find_elements(By.CLASS_NAME, "el-input__inner")[1].send_keys(password)
        # 点击登录
        self.driver.find_element(By.XPATH, "//*[text()='登录']").click()
    def add_user_group(self,name):
        self.name = name
        # 点击用户：
        time.sleep(3)
        self.driver.find_elements(By.CLASS_NAME, "font12")[1].click()
        # 点击用户分组：//*[@id="app"]/section/div[2]/aside/div[2]/div[1]/div/div/ul/li[2]/span
        self.driver.find_element(By.XPATH, "//*[text()='用户分组']").click()
        # 点击添加
        time.sleep(2)
        self.driver.find_element(By.CLASS_NAME, "el-button").click()
        # 输入分组名称
        time.sleep(1)
        self.driver.find_elements(By.CLASS_NAME, "el-input__inner")[2].send_keys(self.name + str(self.uuid_))
        # 点击确定
        self.driver.find_elements(By.CLASS_NAME, "el-button")[2].click()
    def check_name(self):
        time.sleep(2)
        text = self.driver.find_element(By.XPATH, f"//*[text()='社会琳{str(self.uuid_)}']").text
        assert text == self.name + str(self.uuid_)
        time.sleep(15)
if __name__ == '__main__':
     driver = webdriver.Chrome()
     url = "http://121.40.86.4:8899/admin"
     # 实例化对象
     d_crmeb = CRMEB(driver,url)
     # 进行登录
     d_crmeb.login('admin','Aa010903!')
     # 新增用户分组
     d_crmeb.add_user_group("社会琳")
     # 检查是否新增成功
     d_crmeb.check_name()







"""
uuid_ = str(uuid.uuid4()).split('-')[0] # 50e2f5a9
# 初始化驱动
driver = webdriver.Chrome()
# 打开指定网页
url = "http://121.40.86.4:8899/admin"
driver.get(url)
# 设置隐式等待
driver.implicitly_wait(15)
# 最大化窗口
driver.maximize_window()
# 输入账号：
driver.find_elements(By.CLASS_NAME,"el-input__inner")[0].send_keys("admin")
# 输入密码：
driver.find_elements(By.CLASS_NAME,"el-input__inner")[1].send_keys("Aa010903!")
# 点击登录
driver.find_element(By.XPATH,"//*[text()='登录']").click()
# 点击用户：
time.sleep(3)
driver.find_elements(By.CLASS_NAME,"font12")[1].click()
# 点击用户分组：//*[@id="app"]/section/div[2]/aside/div[2]/div[1]/div/div/ul/li[2]/span
driver.find_element(By.XPATH,"//*[text()='用户分组']").click()
# 点击添加
time.sleep(2)
driver.find_element(By.CLASS_NAME,"el-button").click()
# 输入分组名称
time.sleep(1)
driver.find_elements(By.CLASS_NAME,"el-input__inner")[2].send_keys("社会琳" + str(uuid_))
# 点击确定
driver.find_elements(By.CLASS_NAME,"el-button")[2].click()
# 校验是否有添加成功
time.sleep(2)
text = driver.find_element(By.XPATH,f"//*[text()='社会琳{str(uuid_)}']").text
assert text == "社会琳" + str(uuid_)
time.sleep(15)
"""
"""
# 比较啰嗦一点的方法：先定位到父节点
table = driver.find_elements(By.CLASS_NAME,"el-table__body")[0]
# 再去定位到子节点
tr = table.find_elements(By.TAG_NAME,"tr")[-1]
# 再去定位到里面的td
td = tr.find_elements(By.TAG_NAME,"td")[1]
# 再去定位到里面的div
div = td.find_element(By.TAG_NAME,"div")
# 再去定位里面的span
text = div.find_element(By.TAG_NAME,"span").text
assert "社会琳" + str(uuid_) == text
"""